﻿Imports USBConverter.USBConverter

Public Class GUI

    'El puntero del manejador de dispositivo tipo WinUSB
    Private iHandle As IntPtr
    Private Myguid As Guid = New Guid("47D6D24F-61D6-4eb4-B91E-2000366126E6")
    Private ioBuffer() As Byte = {0, 1}
    Dim bResult As Boolean = False

    'Objetos de la clase
    Private USB As USBFunctions = New USBFunctions

    'Métodos de la clase GUI
    Public Sub New()
        Debug.WriteLine("Error: " + CStr(Err.LastDllError))
        ' Llamada necesaria para el Diseñador de Windows Forms.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

        iHandle = USB.USB_init(Myguid, bResult)
        Debug.WriteLine("Error: " + CStr(Err.LastDllError))

    End Sub

    'Botón 1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        If (bResult) Then
            Button1.Enabled = False
            RichTextBox1.AppendText("Inicializado correctamente!" + vbCrLf)
        End If

    End Sub

    'Botón 2
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim BytesWritten As Int32 = 0
        Dim bResult As Boolean = USB.USB_write(iHandle, ioBuffer, BytesWritten)
        RichTextBox1.AppendText("Se escribieron " + CStr(BytesWritten) + " Lineas" + vbCrLf)


    End Sub

End Class